package practicacupfinal;

import java_cup.runtime.*;

%%

%{
	   int yyline() { return yyline; }
	   int yycolumn() { return yycolumn; }
%}

%{
  public void imprime(String str){
    System.out.println(str + " FILA: " + yyline + " COL: " + yycolumn);
  }
%}

%class Scanner

%unicode
%cup 
%line 
%column

/************************* auxiliares *******************************/
letraMin    = [a-z]
letraMay    = [A-Z]
letra       = {letraMin} | {letraMay}
digito      = [0-9]
digitoNZ    = [1-9]
alfanum     = {letra} | {digito}
decimal     = "." ( 0 | [0-9]* ([1-9] | [1-9] 0))   // \. (0 |  {digito}* {digitoNZ}) 
parteExp    = ("e" | "E") {vnatural} 

/********************* identificador y valores ************************/
vnatural    = 0 | {digitoNZ} {digito}*
//vinteger    = "-"? {vnatural}
vfloat = {vnatural} {decimal}? {parteExp}? // {vnatural} ({decimal} {parteExp}? | {parteExp})
vchar  = \'[^\']\'
identificador = {letraMin} {alfanum}*

/******************** palabras reservadas *****************************/
program = "program"
consts = "consts"
const = "const"
vars = "vars"
var = "var"
tipos = "tipos"
tipo = "tipo"
subprograms = "subprograms"
subprogram = "subprogram"
instructions = "instructions"
boolean = "boolean"
character = "character"
natural = "natural"
integer = "integer"
float = "float"
if      = "if"
then    = "then"
else    = "else"
endif   = "endif"
while 	= "while"
do	= "do"
endwhile = "endwhile"
in      = "in"
out     = "out"
call    = "call"
swap1   = "swap1()"
swap2   = "swap2()"
int   = "int"
nat   = "nat"
char  = "char"
true = "true"
false = "false"

/************ operadores ********************/
menor = "<"
mayor = ">"
menigual = "<="
mayigual = ">="
igual = "=="
noigual = "!="
mas = "+"
menos = "-"
mul = "*"
div = "/"
mod = "%"
and = "and"
or = "or"
not = "not"
despder = ">>"
despizq = "<<"

/****************** otros ********************/
dosp = ":"
pcoma = ";"
coma = ","
asig = "="
pap = "("
pcierre = ")"
llaveap = "{"
llavecierre = "}"
corchap = "["
corchcierre = "]"
barrabaja = "_"

%%

[\t\r\n ] {}
#[^\n]*   {}

/********************* valores ************************/
{vnatural}  {return new Symbol(sym.VNATURAL, new Token (yyline(), yycolumn(), yytext()));}
//{vinteger}  {return new Symbol(sym.VINTEGER, new Token (yyline(), yycolumn(), yytext()));}
{vfloat}  {return new Symbol(sym.VFLOAT, new Token (yyline(), yycolumn(), yytext()));}
{vchar} {return new Symbol(sym.VCHAR, new Token (yyline(), yycolumn(), yytext()));}

/******************** palabras reservadas *****************************/
{program} {return new Symbol(sym.PROGRAM, new Token (yyline(), yycolumn(), yytext()));}
{consts} {return new Symbol(sym.CONSTS, new Token (yyline(), yycolumn(), yytext()));}
{const} {return new Symbol(sym.CONST, new Token (yyline(), yycolumn(), yytext()));}
{vars} {return new Symbol(sym.VARS, new Token (yyline(), yycolumn(), yytext()));}
{var} {return new Symbol(sym.VAR, new Token (yyline(), yycolumn(), yytext()));}
{tipos} {return new Symbol(sym.TIPOS, new Token (yyline(), yycolumn(), yytext()));}
{tipo} {return new Symbol(sym.TIPO, new Token (yyline(), yycolumn(), yytext()));}
{subprograms} {return new Symbol(sym.SUBPROGRAMS, new Token (yyline(), yycolumn(), yytext()));}
{subprogram} {return new Symbol(sym.SUBPROGRAM, new Token (yyline(), yycolumn(), yytext()));}
{instructions} {return new Symbol(sym.INSTRUCTIONS, new Token (yyline(), yycolumn(), yytext()));}
{boolean} {return new Symbol(sym.BOOLEAN, new Token (yyline(), yycolumn(), yytext()));}
{character} {return new Symbol(sym.CHARACTER, new Token (yyline(), yycolumn(), yytext()));}
{natural} {return new Symbol(sym.NATURAL, new Token (yyline(), yycolumn(), yytext()));}
{integer} {return new Symbol(sym.INTEGER, new Token (yyline(), yycolumn(), yytext()));}
{float} {return new Symbol(sym.FLOAT, new Token (yyline(), yycolumn(), yytext()));}
{true}  {return new Symbol(sym.TRUE, new Token (yyline(), yycolumn(), yytext()));}
{false}  {return new Symbol(sym.FALSE, new Token (yyline(), yycolumn(), yytext()));}

{if} {return new Symbol(sym.IF, new Token (yyline(), yycolumn(), yytext()));}
{then} {return new Symbol(sym.THEN, new Token (yyline(), yycolumn(), yytext()));}
{else} {return new Symbol(sym.ELSE, new Token (yyline(), yycolumn(), yytext()));}
{endif} {return new Symbol(sym.ENDIF, new Token (yyline(), yycolumn(), yytext()));}
{while} {return new Symbol(sym.WHILE, new Token (yyline(), yycolumn(), yytext()));}
{do} {return new Symbol(sym.DO, new Token (yyline(), yycolumn(), yytext()));}
{endwhile}  {return new Symbol(sym.ENDWHILE, new Token (yyline(), yycolumn(), yytext()));}
{in} {return new Symbol(sym.IN, new Token (yyline(), yycolumn(), yytext()));}
{out} {return new Symbol(sym.OUT, new Token (yyline(), yycolumn(), yytext()));}
{call} {return new Symbol(sym.CALL, new Token (yyline(), yycolumn(), yytext()));}
{swap1} {return new Symbol(sym.SWAP1, new Token (yyline(), yycolumn(), yytext()));}
{swap2} {return new Symbol(sym.SWAP2, new Token (yyline(), yycolumn(), yytext()));}
{char} {return new Symbol(sym.CHAR, new Token (yyline(), yycolumn(), yytext()));}
{int} {return new Symbol(sym.INT, new Token (yyline(), yycolumn(), yytext()));}
{nat} {return new Symbol(sym.NAT, new Token (yyline(), yycolumn(), yytext()));}

/************ operadores ********************/

{menor} {return new Symbol(sym.MENOR, new Token (yyline(), yycolumn(), yytext()));}
{mayor} {return new Symbol(sym.MAYOR, new Token (yyline(), yycolumn(), yytext()));}
{menigual} {return new Symbol(sym.MENIGUAL, new Token (yyline(), yycolumn(), yytext()));}
{mayigual} {return new Symbol(sym.MAYIGUAL, new Token (yyline(), yycolumn(), yytext()));}
{igual} {return new Symbol(sym.IGUAL, new Token (yyline(), yycolumn(), yytext()));}
{noigual} {return new Symbol(sym.NOIGUAL, new Token (yyline(), yycolumn(), yytext()));}
{mas} {return new Symbol(sym.MAS, new Token (yyline(), yycolumn(), yytext()));}
{menos} {return new Symbol(sym.MENOS, new Token (yyline(), yycolumn(), yytext()));}
{mul} {return new Symbol(sym.MUL, new Token (yyline(), yycolumn(), yytext()));}
{div} {return new Symbol(sym.DIV, new Token (yyline(), yycolumn(), yytext()));}
{mod} {return new Symbol(sym.MOD, new Token (yyline(), yycolumn(), yytext()));}
{and} {return new Symbol(sym.AND, new Token (yyline(), yycolumn(), yytext()));}
{or} {return new Symbol(sym.OR, new Token (yyline(), yycolumn(), yytext()));}
{not} {return new Symbol(sym.NOT, new Token (yyline(), yycolumn(), yytext()));}
{despder} {return new Symbol(sym.DESPDER, new Token (yyline(), yycolumn(), yytext()));}
{despizq} {return new Symbol(sym.DESPIZQ, new Token (yyline(), yycolumn(), yytext()));}

/****************** otros ********************/
{pcoma} {return new Symbol(sym.PCOMA, new Token (yyline(), yycolumn(), yytext())); }
{coma} {return new Symbol(sym.COMA, new Token (yyline(), yycolumn(), yytext())); }
{dosp} {return new Symbol(sym.DOSP, new Token (yyline(), yycolumn(), yytext()));}
{asig} {return new Symbol(sym.ASIG, new Token (yyline(), yycolumn(), yytext()));}
{pap} {return new Symbol(sym.PAP, new Token (yyline(), yycolumn(), yytext()));}
{pcierre} {return new Symbol(sym.PCIERRE, new Token (yyline(), yycolumn(), yytext()));}
{llaveap} {return new Symbol(sym.LLAVEAP, new Token (yyline(), yycolumn(), yytext()));}
{llavecierre} {return new Symbol(sym.LLAVECIERRE, new Token (yyline(), yycolumn(), yytext()));}
{corchap} {return new Symbol(sym.CORCHAP, new Token (yyline(), yycolumn(), yytext()));}
{corchcierre} {return new Symbol(sym.CORCHCIERRE, new Token (yyline(), yycolumn(), yytext())); }
{barrabaja} {return new Symbol(sym.BARRABAJA, new Token (yyline(), yycolumn(), yytext())); }

\@ .* {}

{identificador}  {return new Symbol(sym.IDENTIFICADOR,  new Token (yyline(), yycolumn(), yytext()));}

[^]     {return new Symbol(sym.ERROR, new Token (yyline(), yycolumn(), yytext()));} 
/*** [^] {throw new Error("(" + yyline + ", " + yycolumn + ")" + " Caracter no reconocido: "+yytext());}***/


/*** [^]     {return new Symbol(sym.ERROR, yyline(), yycolumn(), yytext());} ***/